<template>
  <div class="shopList">
    <el-table ref="multipleTable" :data="shopList" tooltip-effect="dark" @selection-change="handleSelectionChange" style="width:100%">
      <el-table-column type="selection"></el-table-column>
      <el-table-column label="id" min-width="50">
        <template slot-scope="scope">{{scope.row.id}}</template>
      </el-table-column>
      <el-table-column label="店铺名称" min-width="80">
        <template slot-scope="scope">{{scope.row.shopName}}</template>
      </el-table-column>
      <el-table-column label="员工数" min-width="80">
        <template slot-scope="scope">{{scope.row.member}}</template>
      </el-table-column>
      <el-table-column label="店铺地址" min-width="160">
        <template slot-scope="scope">{{scope.row.address}}</template>
      </el-table-column>
      <el-table-column label="开业日期" min-width="120">
        <template slot-scope="scope">{{scope.row.date}}</template>
      </el-table-column>
      <el-table-column label="营业状态" min-width="80">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isOpen === '是'" type="dafault">{{scope.row.isOpen}}</el-tag>
          <el-tag v-if="scope.row.isOpen === '否'" type="danger">{{scope.row.isOpen}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" content="编辑" placement="bottom" :enterable="false">
            <el-button @click="showEditModal(scope.row.id)" type="primary" size="mini" icon="el-icon-edit" circle></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="删除" placement="bottom" :enterable="false">
            <el-button @click="deleteSingle(scope.$index)" type="danger" size="mini" icon="el-icon-delete" circle></circle></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <div class="tableFoot">
      <div class="paging">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageNo" :page-sizes="[20,40,60,80,100]" :page-size="20" layout="total, sizes, prev, pager, next, jumper" :total="124">
        </el-pagination>
      </div>
      <div class="btnGroup">
        <el-button @click="" type="primary" :disabled="selectData.length===0" icon="el-icon-upload2">批量上架</el-button>
        <el-button @click="deleteMulti" type="danger" :disabled="selectData.length===0" icon="el-icon-delete">批量删除</el-button>
      </div>
    </div>
    <!-- 编辑信息弹出框 -->
    <el-dialog title="收货地址" :visible.sync="showEdit" :modal="false" :close-on-press-escape="false" :close-on-click-modal="false" :center="true">
      <el-form :model="editData" class="editShopListForm">
        <el-form-item label="店铺名称" label-width="120px">
          <el-input v-model="editData.shopName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="员工数" label-width="120px">
          <el-input v-model="editData.member"></el-input>
        </el-form-item>
        <el-form-item label="店铺地址" label-width="120px">
          <el-input v-model="editData.address"></el-input>
        </el-form-item>
        <el-form-item label="开业时间" label-width="120px">
          <el-date-picker v-model="editData.date" type="date" value-format="yyyy-MM-dd" placeholder="选择日期">
        </el-date-picker>
        </el-form-item>
        <el-form-item label="开业状态" label-width="120px">
          <el-select v-model="editData.isOpen" placeholder="请选择活动区域">
            <el-option label="是" value="是"></el-option>
            <el-option label="否" value="否"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="showEdit = false">取 消</el-button>
        <el-button type="primary" @click="confirmEdit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: 'shopList',
    components: {
    },
    data(){
      return {
        showEdit: false,
        shopList: this.$test.shopList,
        selectData: [],
        editData: {},
        pageNo: 1
      }
    },
    methods: {
      deleteSingle(index){
        this.$confirm('删除操作不可恢复, 确定删除?', this.$store.state.warningTip, {
          type: 'warning'
        }).then(() => {
          this.shopList.splice(index,1);
          this.$message.success('删除成功');
        }).catch(()=>{});
      },
      deleteMulti(){
        this.$confirm('删除操作不可恢复, 确定批量删除' + this.selectData.length + '条数据?', this.$store.state.warningTip, {
          type: 'warning'
        }).then(() => {
          this.selectData.forEach(item =>{
            let deleteIndex = this.shopList.findIndex(index => index.id === item.id)
            this.shopList.splice(deleteIndex,1);
          });
          this.$message.success('删除成功');
        }).catch(()=>{});
      },
      showEditModal(id){
        let editIndex = this.shopList.findIndex(index => index.id === id)
        this.editData = this.shopList[editIndex];
        this.showEdit = true;
      },
      confirmEdit(){
        this.showEdit = false;
        this.$message.success('编辑成功');
      },
      handleSelectionChange(selectData){  //批量选择表格
        this.selectData = selectData;
      },
      handleSizeChange(val){
        console.log('每页' + val + '条');
      },
      handleCurrentChange(val) {
        this.shopList.forEach(item =>{
          item.id += 20;
        });
        console.log(`当前页: ${val}`);
      }
    }
  }
</script>

<style lang="scss" scoped>
.shopList{
  .tableFoot{
    .btnGroup{
      float: left;
      margin-top: 20px;
      text-align: left;
    }
    .paging{
      float: right;
      margin-top: 20px;
      text-align: left;
    }
  }
  .editShopListForm{
    padding-right: 50px;
  }
}
</style>